﻿////play the selected medium file
function Play(playtimes, filePath, trackid, playbuttonID, loadingIconID, promptEle) {
    var playerContainer = document.getElementById("div_player_container");

    if (playerContainer == null) {
        document.body.innerHTML += "<div id=\"div_player_container\" style=\"display:none;\"></div>";
    }

    //change the remain times
    var remainTimes = parseInt(document.getElementById(promptEle).innerHTML);
    if (remainTimes > 0) {
        document.getElementById(promptEle).innerHTML = (parseInt(document.getElementById(promptEle).innerHTML) - 1).toString();
    }

    if (parseInt(document.getElementById(promptEle).innerHTML) <= 0) {
        document.getElementById(playbuttonID).src = "../include/exam_image/UnablePlay.jpg";
    }

    if (document.getElementById(trackid).value == "") {
        document.getElementById(trackid).value = "1";
    }
    else {
        if (parseInt(document.getElementById(trackid).value) < parseInt(playtimes)) {
            document.getElementById(trackid).value = (parseInt(document.getElementById(trackid).value) + 1).toString();

        }
        else {
            MediaPlay(filePath, 1, 0);
            return;
        }
    }
    document.getElementById(loadingIconID).style.display = "block";
    document.getElementById(playbuttonID).style.display = "none";
    MediaPlay(filePath, 1, 1); 
    if (document.getElementById("floatTips") != null) {
        initFloatTips("floatTips");
    }
    //setTimeout("document.getElementById(" + loadingIconID + ").style.display = 'none';document.getElementById(" + playbuttonID + ").style.display = 'block'", 3000);
    setTimeout("recoverThePlayImg('" + playbuttonID + "','" + loadingIconID + "')", 10000);
}

function recoverThePlayImg(playid, loadingid) {
    document.getElementById(playid).style.display = "block";
    document.getElementById(loadingid).style.display = "none";
}

function PlayForWarmup(filePath) {
    var playerContainer = document.getElementById("div_player_container");
    if (playerContainer == null) {
        document.body.innerHTML += "<div id=\"div_player_container\" style=\"display:none;\"></div>";
    }
    document.getElementById("imgLoading").style.display = "block";
    document.getElementById("imgPlayButton").style.display = "none";
    MediaPlay(filePath, 1, 1);
    setTimeout("recoverThePlayImg('imgPlayButton','imgLoading')", 10000);
}

//multi media player
//MediaFileUrl: the media file url
//Operator=0:the user will be able to control the player;
//Operator=1:the user won't be able to control the player
function MediaPlay(MediaFileUrl, Operator, autoPlay) {

    if (MediaFileUrl == "")
        return;
    var ParamString
    ParamString = '<object id="object_AviPlayer" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"'
         + 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217"'
         + 'standby="Loading Microsoft Windows Media Player components..."'
         + 'type="application/x-oleobject width=0 height=0">'
         + '<param name="AudioStream" value="-1"/> '
+ '<param name="AutoSize" value="1"/> '
+ '<param name="AutoStart" value="' + autoPlay + '"/> '
+ '<param name="AnimationAtStart" value="0"/> '
+ '<param name="AllowScan" value="-1"/>  '
+ '<param name="AllowChangeDisplaySize" value="0"/>  '
+ '<param name="AutoRewind" value="0"/>  '
+ '<param name="Balance" value="0"/>   '
+ '<param name="BaseURL" value=""/>  '
+ '<param name="BufferingTime" value="5"/>  '
+ '<param name="CaptioningID" value=""/>  '
+ '<param name="ClickToPlay" value="1"/>   '
+ '<param name="CursorType" value="32512"/>   '
+ '<param name="CurrentPosition" value="-1"/>   '
+ '<param name="CurrentMarker" value="0"/>   '
+ '<param name="DefaultFrame" value="1"/>   '
+ '<param name="DisplayBackColor" value="0"/>   '
+ '<param name="DisplayForeColor" value="16777215"/>   '
+ '<param name="DisplayMode" value="0"/>   '
+ '<param name="DisplaySize" value="0"/>   '
+ '<param name="Enabled"  value="' + Operator + '"/>   '
+ '<param name="EnableContextMenu" value="-1"/>   '
+ '<param name="EnablePositionControls" value="0"/>   '
+ '<param name="EnableFullScreenControls" value="0"/>   '
+ '<param name="EnableTracker" value="1"/>   '
+ '<param name="Filename" value="' + MediaFileUrl + '" />'
+ '<param name="InvokeURLs" value="-1"/>   '
+ '<param name="Language" value="-1"/>   '
+ '<param name="Mute" value="0"/>   '
+ '<param name="PlayCount" value="1"/>   '
+ '<param name="PreviewMode" value="0"/>   '
+ '<param name="Rate" value="1"/>   '
+ '<param name="SAMILang" value=""/>   '
+ '<param name="SAMIStyle" value=""/>   '
+ '<param name="SAMIFileName" value=""/>   '
+ '<param name="SelectionStart" value="0"/>   '
+ '<param name="SelectionEnd" value="true"/>   '
+ '<param name="SendOpenStateChangeEvents" value="-1"/>   '
+ '<param name="SendWarningEvents" value="-1"/>   '
+ '<param name="SendErrorEvents" value="-1"/>   '
+ '<param name="SendKeyboardEvents" value="0"/>   '
+ '<param name="SendMouseClickEvents" value="0"/>   '
+ '<param name="SendMouseMoveEvents" value="0"/>   '
+ '<param name="SendPlayStateChangeEvents" value="-1"/>  '
+ '<param name="ShowCaptioning" value="0"/>   '
+ '<param name="ShowControls" value="1"/>   '
+ '<param name="ShowAudioControls" value="1"/>   '
+ '<param name="ShowDisplay" value="1"/>   '
+ '<param name="ShowGotoBar" value="1"/>   '
+ '<param name="ShowPositionControls" value="1"/>   '
+ '<param name="ShowStatusBar" value="1"/>   '
+ '<param name="ShowTracker" value="1"/>   '
+ '<param name="TransparentAtStart" value="0"/>   '
+ '<param name="VideoBorderWidth" value="0"/>   '
+ '<param name="VideoBorderColor" value="0"/>   '
+ '<param name="VideoBorder3D" value="0"/>   '
+ '<param name="Volume" value="-70"/>   '
+ '<param name="WindowlessVideo" value="1"/>   '
+ '</object>';

    document.getElementById("div_player_container").innerHTML = ParamString;
}

/////
//function $(id) {
//    return document.getElementById(id);
//}